home *** CD-ROM | disk | FTP | other *** search
- /*
- File: TwoByteFonts.c
-
- Contains: QuickDraw GX to PostScript conversion code.
- File contains code necessary for construction and use
- of Two Byte fonts (type-0) in PostScript.
-
- Version: Technology: Quickdraw GX 1.1.x
-
- Copyright: © 1991-1997 by Apple Computer, Inc., all rights reserved.
- */
-
- #include "GXToPSBuildConfig.h"
- #include <string.h>
- #include "IOUtilities.h"
- #include "GXExceptions.h"
- #include "GXPrintingUniverse.h"
- #include "FontDatabase.h"
- #include "FontHandler.h"
- #include "FontHandlerPrivate.h"
- #include "FontHandlerVariations.h"
- #include "FHResources.h"
- #include <GXGraphics.h>
-
- #ifdef resumeLabel
- #undef resumeLabel
- #endif
- #define resumeLabel(exception)
-
-
- //<FF>
- /*******************************************
-
- Routine counts how many glyphs are used by the
- document for theFont.
-
- ********************************************/
- OSErr FHCountDocGlyphs(TFontHandlerHdl hFHRec, fhFont theFont, long *nDocGlyphs);
- OSErr FHCountDocGlyphs(TFontHandlerHdl hFHRec, fhFont theFont, long *nDocGlyphs)
- {
- OSErr status;
- gxFont realFont;
- long glyphCount;
- long dbIndex;
- unsigned long *glyphBits;
-
- realFont = FHGetSnapShotFont(hFHRec, theFont, &dbIndex);
- glyphCount = GXCountFontGlyphs(realFont);
-
- status = FontDbaseGetGlyphBits((*hFHRec)->docDbase, realFont, dbIndex, &glyphBits, nil);
- nrequire(status, failed_getBits);
-
- *nDocGlyphs = CountGlyphBits(glyphBits, glyphCount);
-
- failed_getBits:
- return(status);
-
-
- }//FHCountDocGlyphs
-
-
- //<FF>
- /***************************************
-
- Function: FHGenerateTwoByteFontName
-
- Function generates the name for a synthetic Two Byte font
- for a particular document font.
-
- ****************************************/
- long FHGenerateTwoByteFontName(TFontHandlerHdl hFHRec, fhFont theFont, unsigned char name[256])
- {
- #pragma unused(hFHRec)
- long nameLength;
-
- memcpy(name, "GX2ByteFont$", 11); // base for name is /GX2ByteFont$
- HexBlockMove((unsigned char*)&theFont, name + 11, sizeof(fhFont)); // Suffix is hex of theFont
-
- nameLength = 11 + 2 * sizeof(fhFont);
-
- return(nameLength);
-
- }//FHGenerateTwoByteFontName
-
-
-
- //<FF>
- /****************************************************
-
- Function: FHMakeTwoByteFont
-
- Function makes a two byte PostScript font out of all of the
- printer fonts for a particular real font if it is possible.
-
- It is possible if:
- 1: The printer can support two byte fonts.
- 2: There is more than one printer font for the document font.
- 3: All Printer Fonts for the document font are resident and encoded on the printer.
- Two byte font will be made out of all printer fonts indexed zero through N where
- N is the biggest index of a printer font that is resident and encoded.
-
- hFHRec: Handle to the font handler context.
- theFont: The font to make the two byte font from.
-
- *****************************************************/
- OSErr FHMakeTwoByteFont(TFontHandlerHdl hFHRec, fhFont theFont)
- {
- OSErr status = noErr;
- TPrinterFontRec *printerFont;
- long nPrFonts; // Number of printer fonts for the font.
- unsigned char fontName[256]; // Name for a particular printer font.
- long nameLength; // length of a name.
- long idx;
- Boolean buildFont = false; // Should we build the font at all?
- TRDParams rdParams;
- long nDocGlyphs;
-
- rdParams.rdMap = (*hFHRec)->rdMap;
- rdParams.resType = kScriptResType;
- rdParams.resID = kFHScriptResID;
- rdParams.rdFlags = eRDnoOptions;
-
- nPrFonts = FHCountPrinterFonts(hFHRec, theFont);
-
- /** No use making one if we don't need it or the printer can't support it **/
- if ( (nPrFonts <= 1) || !((*hFHRec)->useTypeZeroFonts) )
- return(noErr);
-
- /**
- If the probability of needing to swap printer fonts is less
- than 25% don't bother with two byte font. (# glyphs in doc < 384)
- Trying guestimage when swapping fonts will be more efficient than
- always using 2 byte strings for text.
- **/
- status = FHCountDocGlyphs(hFHRec, theFont, &nDocGlyphs);
- nrequire(status, failed_count);
- if (nDocGlyphs < 384)
- return(noErr);
-
-
- /** Put the font dictionary for each printer font in the group on the operand stack **/
-
- for (idx = 0; idx < nPrFonts; ++idx) {
-
- status = FHGetIndexedPrinterFont(hFHRec, theFont, idx, &printerFont, nil);
- nrequire(status, failed_GetPrFont);
-
- /** Only group toghether printer fonts that are encoded (and not already two byte fonts) **/
-
- if ( (printerFont->info & fontIsEncoded) && !(printerFont->info & fontCantBeRencoded) ) {
-
- printerFont->info |= fontIsTwoByteMember; // Mark as two byte font member.
-
- nameLength = FHGeneratePrinterName(printerFont, fontName); // Watch for hFHRec moving - if it can, lock it.
- rdParams.resIndex = kFindFont;
- status = RDResPrintf(&rdParams, fontName, nameLength);
- nrequire(status, failed_findFont);
- buildFont = true;
-
- } else {
-
- /****
- If we found a printer font that wasn't encoded, exit the loop
- We will build two byte font for first N fonts in group,
- rest will be handled by swapping
- ****/
- break;
-
- }//end if
-
- }//end for
-
- /** If we can build it, do it! **/
-
- if (buildFont) {
-
- /* Now build the two byte font out of all of the font dictionaries on the stack */
-
- nameLength = FHGenerateTwoByteFontName(hFHRec, theFont, fontName);
- rdParams.resIndex = kMakeComposite;
- status = RDResPrintf(&rdParams, nPrFonts, fontName, nameLength); // Call MakeCompositeFont in PS.
- nrequire(status, failed_makeComposite);
-
- }//end if
-
- failed_count:
- failed_makeComposite:
- failed_findFont:
- failed_GetPrFont:
-
- return(status);
-
- }//FHMakeTwoByteFont
-